package tankattack.sprites;

import gamepack.*;
import java.awt.*;
import java.util.Vector;

/** @author Somanath
*/

// Dependency : None
public class FlexiShape extends Sprite {

static {
	   //System.out.println("#########################  Flexi.java Compiled ##########################");
	   }

    // <Data name="spawnformat"> x=%d,y=%d # polygon="%s" " </Data>
	// where polygon is of the format = "npoints,xpoint[0],ypoint[0],xpoint[1],ypoint[1],.... "
	public FlexiShape() {		
		
		setAttribute( "BLOCK" );
		SpriteArgs sa = Sprite.getArgs();

		int npoints = 3;
		int[] xpoints = new int[npoints];
		int[] ypoints = new int[npoints];
		xpoints[0] = 0; ypoints[0] = 0;
		xpoints[0] = 28; ypoints[0] = 0;
		xpoints[0] = 28; ypoints[0] = 28;
		
		Polygon p = new Polygon( xpoints, ypoints, npoints) ; 
		
		Rectangle bounds = p.getBounds();
		int width = bounds.width;
		int height = bounds.height;
		
		//int width = Integer.parseInt( sa.strMap.get("width").toString() );
		//int height = Integer.parseInt( sa.strMap.get("height").toString()  );
		// Create the picture of the Flexibrick at runtime.
		Color fillColor = Color.gray;
		Color borderColor = Color.black;
		Image img = Application.createImage(width,height,fillColor);
		Graphics g = img.getGraphics();
		if( g == null )	throw new RuntimeException(" g == null in flexibrick ");
		g.setColor(borderColor);
		g.drawRect(0,0,width-1,height-1);
		g.drawPolygon( p );

        // Store the image data in attribute 'res'
		res = new Resource();   // This is set to null in base class Sprite
		res.img = new CImage[1][1];
		res.img[0][0] = new CImage(img,0,0,new Rectangle(0,0,width,height));

		startSprite();
	}
	
}